package set;

import java.util.Set;
import java.util.TreeSet;

class Person implements Comparable<Person>{
	int age;
	
	public Person(int age) {
		super();
		this.age = age;
	}

	@Override
	public String toString() {
		return "Person [age=" + age + "]";
	}

	@Override
	public int compareTo(Person o) {
		return this.age - o.age;
	}
	
}

public class TreeSetTest {
	public static void main(String[] args) {
		Set<Person> set = new TreeSet<Person>();
		set.add(new Person(10));
		set.add(new Person(13));
		set.add(new Person(12));
		set.add(new Person(16));
		System.out.println(set);
		
		Set<Integer> set2 = new TreeSet<Integer>();
		set2.add(10);
		System.out.println(set2);
		set2.add(20);
		System.out.println(set2);
		set2.add(40);
		System.out.println(set2);
		set2.add(30);
		System.out.println(set2);
	}
}
